package pickbook.model;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

//관리자 서비스 implements 후 정의
@Service
public class AdminServiceImpl implements AdminService {
	
	@Resource(name="adminDAOImpl")
	private AdminDAO adminDAO;
	
	@Resource(name="memberDAOImpl")
	private MemberDAO memberDAO;
	
	@Resource(name="saleBookDAOImpl")
	private SaleBookDAO saleBookDAO;
	
	@Resource(name="buyBookDAOImpl")
	private BuyBookDAO buyBookDAO;

	/**
	 * method : loginAdmin
	 * comment : 관리자 로그인 메서드
	 * 
	 * @return
	 * 
	 * @author 제형규
	 * @date 2014-07-04
	 */
	@Override
	public AdminVO loginAdmin(AdminVO avo) {
		return adminDAO.loginAdmin(avo);
	}
	
	/**
	 * method : getRecentSaleBookList
	 * comment : pageNo를 통해 최신 순으로 판매도서 리스트를 받아오는 메서드
	 * 
	 * @param pageNo
	 * @return
	 * 
	 * @author 제형규
	 * @date 2014-07-04
	 */
	@Override
	public ListVO getRecentSaleBookList(String pageNo) {
		
		if(pageNo==null||pageNo=="") pageNo="1";
		
		List<SaleBookVO> list=saleBookDAO.getAllBookList(pageNo);//전체 판매도서 목록 반환

		int total=saleBookDAO.totalSaleContent();
		PagingBean paging=new PagingBean(total,Integer.parseInt(pageNo));
		
		ListVO lvo=new ListVO(list, paging);//목록 페이징
		
		return lvo;
		
	}
	
	/**
	 * method : getRecentBuyBookList
	 * comment : pageNo를 통해 최신 순으로 희망도서 리스트를 받아오는 메서드
	 * 
	 * @param pageNo
	 * @return
	 * 
	 * @author 제형규
	 * @date 2014-07-04
	 */
	@Override
	public ListVO getRecentBuyBookList(String pageNo) {
		
		if(pageNo==null||pageNo=="") pageNo="1";
		
		List<BuyBookVO> list=buyBookDAO.getAllBookList(pageNo);//전체 희망도서 목록 반환
		
		int total=buyBookDAO.totalBuyContent();
		PagingBean paging=new PagingBean(total,Integer.parseInt(pageNo));
		
		ListVO lvo=new ListVO(list, paging);//목록 페이징
		
		return lvo;
		
	}
	
	/**
	 * method : deleteBuyBook
	 * comment : 희망도서 삭제하는 메서드
	 * 
	 * @param no
	 * @return
	 * 
	 * @author 제형규
	 * @date 2014-07-04 
	 */
	@Override
	public void deleteBuyBook(int no) {
		buyBookDAO.deleteBook(no);//희망도서 삭제
	}
	
	/**
	 * method : deleteSaleBook
	 * comment : 판매도서 삭제하는 메서드
	 * 
	 * @param no
	 * @return
	 * 
	 * @author 제형규
	 * @date 2014-07-04 
	 */
	@Override
	public void deleteSaleBook(int no) {
		saleBookDAO.deleteBook(no);//판매도서 삭제
	}

	@Override
	public ListVO memberList(String pageNo) {
		if(pageNo==null||pageNo=="") 
			pageNo="1";
		List<MemberVO> list=memberDAO.memberList(pageNo);
		int total=memberDAO.totalContent();
		PagingBean paging=new PagingBean(total,Integer.parseInt(pageNo));
		ListVO lvo=new ListVO(list, paging);
		return lvo;
	}
	/**
	 * method : deleteMember
	 * comment : 회원 삭제 메서드
	 * 
	 * @param id
	 * @return
	 * 
	 * @author 제형규
	 * @date 2014-07-04 
	 */
	@Override
	public void deleteMember(String id) {
		memberDAO.withdraw(id);
	}

	/**
	 * method : searchMember
	 * comment : 회원 검색 메서드
	 * 
	 * @param factor
	 * @return
	 * 
	 * @author 제형규
	 * @date 2014-07-04 
	 */
	@Override
	public ListVO searchMember(String factor, String pageNo){
		if(pageNo==null||pageNo=="") 
			pageNo="1";
		List<MemberVO> list=memberDAO.searchMember(factor, pageNo);
		int total=memberDAO.totalSearchContent(factor);
		PagingBean paging=new PagingBean(total,Integer.parseInt(pageNo));
		ListVO lvo=new ListVO(list, paging);
		System.out.println(lvo);
		return lvo;
	}
	/**
	 * method : searchSaleBook
	 * comment : 판매 도서 검색 메서드
	 * 
	 * @param factor
	 * @return
	 * 
	 * @author 제형규
	 * @date 2014-07-04 
	 */
	@Override
	public ListVO searchSaleBook(String factor, String pageNo){
		if(pageNo==null||pageNo=="") 
			pageNo="1";
		List<SaleBookVO> list=saleBookDAO.searchSaleBook(factor, pageNo);
		int total=saleBookDAO.totalSearchContent(factor);
		PagingBean paging=new PagingBean(total,Integer.parseInt(pageNo));
		ListVO lvo=new ListVO(list, paging);
		System.out.println(lvo);
		return lvo;
	}
	/**
	 * method : searchBuyBook
	 * comment : 희망 도서 검색 메서드
	 * 
	 * @param factor
	 * @return
	 * 
	 * @author 제형규
	 * @date 2014-07-04 
	 */
	@Override
	public ListVO searchBuyBook(String factor, String pageNo){
		if(pageNo==null||pageNo=="") 
			pageNo="1";
		List<BuyBookVO> list=buyBookDAO.searchBuyBook(factor, pageNo);
		int total=buyBookDAO.totalSearchContent(factor);
		PagingBean paging=new PagingBean(total,Integer.parseInt(pageNo));
		ListVO lvo=new ListVO(list, paging);
		System.out.println(lvo);
		return lvo;
	}
}
